package guiscreens;

import java.awt.CardLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

import com.jgoodies.forms.factories.FormFactory;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.RowSpec;

import dao.ExecuteQuery;
import dao.ResultSetTable;

/**
 * This class handels the viewing of the category reports.
 * 
 * @author Lee
 * @version 1.0
 */
public class ViewCatReport extends JPanel {

	private CardLayout c1;
	private JPanel basePanel;
	private JFrame thisFrame;

	/**
	 * Create the panel.
	 */
	public ViewCatReport(final CardLayout c1, final JPanel basePanel, 
			final JFrame thisFrame) {
		this.c1 = c1;
		thisFrame.setTitle("Category Report");
		thisFrame.setBounds(login.XCENTER - 300, login.YCENTER - 300, 600, 600);
		this.basePanel = basePanel;
		this.thisFrame = thisFrame;
		setBackground(Color.WHITE);
		setLayout(new FormLayout(new ColumnSpec[] {
				ColumnSpec.decode("47px"),
				ColumnSpec.decode("69px"),
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("max(41dlu;default)"),
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("max(34dlu;default)"),
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("max(33dlu;default)"),
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,},
			new RowSpec[] {
				FormFactory.LINE_GAP_ROWSPEC,
				RowSpec.decode("18px"),
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("max(23dlu;default)"),
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("max(67dlu;default)"),
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,}));

		ResultSet results = ExecuteQuery.viewCatReport();
		final ResultSetTable table = new ResultSetTable(results, false, true, false, false);
		add(table, "2, 6, 11, 1, left, fill"); 
		
		JButton btnDone = new JButton("Done");
		btnDone.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent event)
			{
				thisFrame.setTitle("Welcome!");
				
				c1.first(basePanel);
				thisFrame.setBounds(MainWindow.XCENTER - 275, MainWindow.YCENTER - 300, 550, 600);
			}
		});
		add(btnDone, "14, 8");
	}

}
